package com.topisv.tms.service.stock.check;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.AreaGroup;
import com.topisv.tms.entity.Customers;
import com.topisv.tms.entity.stock.check.CheckPlanItem;
import com.topisv.tms.repository.AreaGroupDao;
import com.topisv.tms.repository.CustomersDao;
import com.topisv.tms.repository.stock.check.CheckPlanItemDao;

@Component
@Transactional(readOnly = true)
public class CheckPlanItemService {

	@Autowired
	private CheckPlanItemDao checkPlanItemDao;
	@Autowired
	private CustomersDao customersDao;
	@Autowired
	private AreaGroupDao areaGroupDao;

	/**
	 * 查询盘点明细
	 * @param planCode 计划编号
	 * @return
	 */
	public List<CheckPlanItem> loadByPlanCode(String planCode) {
		List<CheckPlanItem> itemList=this.checkPlanItemDao.loadByPlanCode(planCode);
		
		for (CheckPlanItem item : itemList) {
			this.setDetail(item);
		}
		
		return itemList;
	}
	
	/**
	 * 设置属性
	 * @param item
	 */
	public void setDetail(CheckPlanItem item) {
		//customer
		String customerCode=item.getCustomerCode();
		Customers customer=this.customersDao.findByCustomerCode(customerCode);
		item.setCustomer(customer);
		
		//warehouse
		String warehouseCode=item.getWarehouseCode();
		AreaGroup warehouse=this.areaGroupDao.findByGroupCode(warehouseCode);
		item.setWarehouse(warehouse);
	}

}